package cn.share.life.module.images.controller;

import cn.share.life.module.images.dal.GirlImagesDO;
import cn.share.life.module.images.dal.vo.GirlImagesPageReqVO;
import cn.share.life.module.images.dal.vo.GirlImagesRespVO;
import cn.share.life.module.images.dal.vo.GirlImagesSaveReqVO;
import cn.share.life.module.images.service.GirlImagesService;
import cn.share.life.common.pojo.CommonResult;
import cn.share.life.common.pojo.PageResult;
import cn.share.life.common.util.object.BeanUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;

import static cn.share.life.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 美女图片")
@RestController
@RequestMapping("/front/girl-images")
@Validated
public class GirlImagesController {

    @Resource
    private GirlImagesService girlImagesService;

    @PostMapping("/init")
    @Operation(summary = "根据目录初始化美女图片")
    public CommonResult<Integer> initGirlImages(@RequestBody GirlImagesSaveReqVO createReqVO) {
        return success(girlImagesService.initGirlImages(createReqVO));
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除美女图片")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteGirlImages(@RequestParam("id") String id) {
        girlImagesService.deleteGirlImages(id);
        return success(true);
    }

    @GetMapping("/page")
    @Operation(summary = "获得美女图片分页")
    public CommonResult<PageResult<GirlImagesRespVO>> getGirlImagesPage(@Valid GirlImagesPageReqVO pageReqVO) {
        PageResult<GirlImagesDO> pageResult = girlImagesService.getGirlImagesPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, GirlImagesRespVO.class));
    }

    @PostMapping("/update/{id}/{classify}")
    @Operation(summary = "修改美女图片分类(分类:0默认1美女 2胸 3b 4x 5其他)")
    @Parameter(name = "id", description = "主键", required = true, example = "1024")
    @Parameter(name = "classify", description = "分类", required = true, example = "1美女 2胸 3b 4x 5其他")
    public CommonResult<Integer> updateGirlImages(@PathVariable("id") String id, @PathVariable("classify") String classify) {
        return success(girlImagesService.updateGirlImages(id, classify));
    }

    @PostMapping("/syncWeb")
    @Operation(summary = "同步网页链接信息")
    @Parameter(name = "url", description = "分类", required = true, example = "1美女 2胸 3b 4x 5其他")
    public CommonResult<Integer> syncWebInfo(@RequestParam("url") String url) {
        return success(girlImagesService.syncWebInfo(url));
    }
}